<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品信息编辑</title>
<#include "/WEB-INF/content/module-edit.html">
<script type="text/javascript">
var sysStatus = [
    {"id":"0","text":"正常"},
    {"id":"1","text":"禁用"}
];
var oper=[
	{"id":"0","text":"上架"},
	{"id":"1","text":"下架"}
];
var pos=[
	{"id":"0","text":"是"},
   	{"id":"1","text":"否"}
];
var typeTree=[
	<#list map.typeTree as item>
		{"id":"${item.id}","text":"${item.text}","children":[
			<#list item.children as ite>
				{"id":"${ite.id}","text":"${ite.text}"}<#if ite_has_next>,</#if>
			</#list>
		]}<#if item_has_next>,</#if>
	</#list>
];
var areaTree=[
	<#list map.areaTree as item>
		{"id":"${item.id}","text":"${item.text}","children":[
			<#list item.children as ite>
				{"id":"${ite.id}","text":"${ite.text}","children":[
					<#list ite.children as it>
						{"id":"${it.id}","text":"${it.text}","children":[
             				<#list it.children as i>
           						{"id":"${i.id}","text":"${i.text}"}<#if i_has_next>,</#if>
           					</#list>						                                                 
						]}<#if it_has_next>,</#if>
					</#list>
				]}<#if ite_has_next>,</#if>
			</#list>
		]}<#if item_has_next>,</#if>
	</#list>
];
$(function() {
  	$("#status").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:sysStatus
  	}); 
  	$("#productstatus").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:oper
  	});
  	$("#isrecommend").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
  		data:pos
  	});
  	
  	$("#aid1").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
  		data:areaTree,
  		onChange:function(data){
			$("#s2").css("display","none");
			$("#s3").css("display","none");
			$("#s4").css("display","none");
			$("#aid2").combobox('setValue',"");
  			for(var i in areaTree){
  				if(areaTree[i].id==data){
  					var tree=areaTree[i].children;
  					if(tree.length>0){
  	  					$("#aid2").combobox('loadData',tree);
  	  					$("#s2").css("display","block");
  					}
  				}
  			}
  		}
  	});	
	$("#aid2").combobox({
	  		valueField : 'id',
	  		textField : 'text',
	  		editable:false,
	        panelHeight:'auto',
	        <#if map.secondData??>
			data:${map.secondData},
			</#if>
	        onChange:function(data){
				$("#s3").css("display","none");
 				$("#s4").css("display","none");
 				$("#aid3").combobox('setValue',"");
	        	var datas=$("#aid2").combobox("getData");
	  			for(var i in datas){
	  				if(datas[i].id==data){
	  					var tree=datas[i].children;
	  					if(tree.length>0){
	  	  					$("#aid3").combobox('loadData',tree);
	  	  					$("#s3").css("display","block");
	  					}
	  				}
	  			}
	        }
		});  	
	$("#aid3").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
        <#if map.thirdData??>
		data:${map.thirdData},
		</#if>        
        onChange:function(data){
        	$("#s4").css("display","none");
        	$("#aid4").combobox('setValue',"");
        	var datas=$("#aid3").combobox("getData");
  			for(var i in datas){
  				if(datas[i].id==data){
  					var tree=datas[i].children;
  					if(tree.length>0){
  	  					$("#aid4").combobox('loadData',tree);
  	  					$("#s4").css("display","block");
  					}
  				}
  			}
        }
	});  
	$("#aid4").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
        <#if map.fourthData??>
		data:${map.fourthData}
		</#if>        
	}); 
  	
  	$("#parent").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
  		data:typeTree,
  		onChange:function(data){
  			for(var i in typeTree){
  				if(typeTree[i].id==data){
  					$("#ttid").combobox({
  				  		valueField : 'id',
  				  		textField : 'text',
  				  		editable:false,
  				        panelHeight:'auto',
  				      	required:true,
  				        value:"",
  				  		data:typeTree[i].children
  					});
  				}
  			}
  		}
  	});	  
    <#if object.tid?exists&&object.tid!="">
    var sub;
    var parent=$("#parent").val();
    for(var i in typeTree){
    	if(typeTree[i].id==parent){
    		sub=typeTree[i].children;
    	}
    }
	$("#ttid").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
        data:sub,
        required:true
	});    
	<#else>
	$("#ttid").combobox({
  		valueField : 'id',
  		textField : 'text',
  		editable:false,
        panelHeight:'auto',
        required:true
	});        
	</#if>  
  	$('#productamount').numberspinner({editable:true,min:1,increment:1 });
  	$("#productprice").numberbox({min:0,precision:2});
  	$("#productshowprice").numberbox({min:0,precision:2});
 });
</script>
<style>
.input-width{
	width: 95%;
}
</style>
 
</head>
<body class="easyui-layout">
	<div region="north" id="toolbar" style="background-color: #eee; padding: 5px; overflow: hidden;" border="false">
		<#if object.tid?exists&&object.tid!="">
			<@auth code="terminal:update">
				<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-add" style="border: 1px solid #ccc" onclick="javascript:save()">保存</a>
			</@auth>
		<#else>
			<@auth code="terminal:create">
				<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-add" style="border: 1px solid #ccc" onclick="javascript:save()">保存</a>
			</@auth>
		</#if>
		<a href="javascript:void(0);" class="easyui-linkbutton" plain="true" iconCls="icon-edit" style="border: 1px solid #ccc" onclick="javascript:cancel()">关闭</a>
	</div>
	<div region="center">
		<div id="p" class="easyui-panel" style="background: #fafafa; padding: 10px" fit="true" toolbar="#toolbar">
			<form id="form" method="post">
				<input type="hidden" id="_id" name="tid" value="${object.tid!}"/>
				<table class="form" cellspacing="0" style="width: 100%">
					<tbody style="border: 1px solid #ccc">
						<tr>
							<td class="label">设备编号:</td>
							<td><input id="serialno" name="serialno" value="${(object.serialno)!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>
							<td class="label">所属类型：</td>
							<td><input id="parent" value="${(map.typeparent)}">
								<input id="ttid" name="ttid" value="${(object.ttid)!}"/>
							</td>
							<td class="validate">*</td>							
						</tr>
						<tr>
							<td class="label">所属地区：</td>
							<td colspan="4">
								<input id="aid1" value="${map.aid1!}"/>
								<input id="aid2" value="${map.aid2!}"/>
								<input id="aid3" value="${map.aid3!}"/>
								<input id="aid4" name="aid" value="${(object.aid)!}" required="true"></td>
							<td class="validate">*</td>						
						</tr>							
						<tr>
							<td class="label">经度:</td>
							<td><input id="longitude" name="longitude" value="${(object.longitude)!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>
							<td class="label">纬度:</td>
							<td><input id="latitude" name="latitude" value="${(object.latitude)!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>
						</tr>
						<tr>
							<td class="label">联系人：</td>
							<td><input id="linkman" name="linkman" value="${object.linkman!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>						
							<td class="label">联系电话：</td>
							<td><input id="linktel" name="linktel" required="true" value="${object.linktel!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>
						</tr>
						<tr>
							<td class="label">入驻小区日期:</td>
							<td><input id="entertime" name="entertime" class="easyui-datebox" value="${object.entertime!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>
							<td class="label">小区名称:</td>
							<td><input id="community" name="community" class="easyui-validatebox" value="${object.community!}" class="easyui-validatebox" required="true"/></td>
							<td class="validate">*</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
</body>
</html>